package com.design.service;

import com.design.entity.PayReq;
import com.design.service.impl.AliPayService;
import com.design.service.impl.JdPayService;
import com.design.service.impl.WeixinPayService;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * 支付工厂类
 */
public class PayFactory {
    public static Map<String, IPayService> payServiceMap;
    static {
        payServiceMap = new HashMap<>();
        payServiceMap.put("weixin", new WeixinPayService());
        payServiceMap.put("ali", new AliPayService());
        payServiceMap.put("jd", new JdPayService());
    }
    public IPayService getPayService(String payType) {
        IPayService payService = payServiceMap.get(payType);
        if (payService == null) {
            throw new IllegalArgumentException("不支持的支付类型");
        }
        return payService;
    }

    public static void main(String[] args) {
        PayReq payReq = new PayReq("123456", new BigDecimal(100.00), "weixin");
        IPayService payService = new PayFactory().getPayService(payReq.getPayType());
        payService.pay(payReq);
    }
}
